package com.chen.controller;

import com.chen.pojo.dto.LoginDto;
import com.chen.pojo.vo.LoginUserVo;
import com.chen.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chen
 * @version 1.0
 * @date 2025/8/15
 * 登录业务
 */
@Slf4j
@RestController
@RequestMapping("/api/user-service/user")
@Tag(name = "用户登录接口", description = "处理用户登录相关操作")
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @Operation(
            summary = "用户登录",
            description = "根据用户名和密码进行用户登录验证，成功后返回用户信息和访问令牌"
    )
    public LoginUserVo login(
            @Parameter(description = "登录请求参数，包含用户名和密码")
            @RequestBody LoginDto dto
    ) {
        log.info("当前登录用户：{}", dto.getLoginName());
        LoginUserVo result = userService.login(dto);
        log.info("用户：{} 登录成功！", dto.getLoginName());
        return result;
    }
}
